# Maintainer: Jianfeng Liu <liujianfeng1994@gmail.com>
# Contributor: Olivier Michel <Olivier.Michel@cyberbotics.com>

_realname=libzip
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.1.3
pkgrel=1
pkgdesc="A C library for reading, creating, and modifying zip archives (mingw-w64)"
url="http://www.nih.at/libzip/index.html"
license=('BSD')
arch=('any')
depends=("${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-dlfcn")
options=('staticlibs' '!libtool')
source=("http://www.nih.at/${_realname}/${_realname}-${pkgver}.tar.xz")
sha256sums=('729a295a59a9fd6e5b9fe9fd291d36ae391a9d2be0b0824510a214cfaa05ceee')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  
  autoreconf -fi
}

build() {
  mkdir -p "${srcdir}/build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${CARCH}"

  make DESTDIR="${pkgdir}" install

  # preserve old header path for compatibility
  # ln -s ${MINGW_PREFIX}/lib/libzip/include/zipconf.h "${pkgdir}${MINGW_PREFIX}/include/zipconf.h"
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}/${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
